﻿
var prizeJson = null;

$(document).ready(function () {
    $.ajax({
        type: "post",
        data: { action: "GetList" },
        dataType: "json",
        url: "../../Ajax/TaskTypeAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                var json = data.json;
                var tbody = "";
                $.each(json, function (k, v) {
                    tbody += "<tr>"
                    tbody += "<td><lable name='lblID'>";
                    tbody += v.ID;
                    tbody += "</label></td>";
                    tbody += "<td><a href='javascript:void(0)' onclick='javascript:EditLblTypeID(\"" + v.ID + "\",\"" + v.Name + "\");GetTaskList(1)'><lable name='lblName'>";
                    tbody += v.Name;
                    tbody += "</label></a></td>";
                    tbody += "<td>";
                    tbody += "<input type='button' onclick='Update(this)' value='更新'><input type='button' onclick='Delete(this)' value='删除'>";
                    tbody += "</td>";
                    tbody += "</tr>"
                })
                $("#tb1").empty().append(tbody);
                if ($("#tb1").find("lable[name=lblID]").length > 0) {
                    EditLblTypeID($("#tb1").find("lable[name=lblID]").first().text(), $("#tb1").find("lable[name=lblName]").first().text());
                    GetTaskList(1);
                }

            }
        },
        complete: function () {
        },
        error: function () {
        }
    });

    $("#btnAdd").click(function () {
        Edit(null);
    })

    $("#btnAddTask").click(function () {
        EditTask(null);
    })

    $("#btnCondition").click(function () {
        EditCondition(null);
    })
})


function UpdateTask(contr) {
    EditTask(contr);
}

function EmptyUnitChecked(val, text) {
    if (val == text)
        return "checked='checked'";
}

function EditTask(contr) {
    var id = $(contr).parent().parent().find("lable[name=lblName]").first().attr('id');
    var name = $(contr).parent().parent().find("lable[name=lblName]").first().text();
    var startTime = $(contr).parent().parent().find("lable[name=lblStartTime]").first().text();
    var endTime = $(contr).parent().parent().find("lable[name=lblEndTime]").first().text();
    var isRemind = $(contr).parent().parent().find("lable[name=lblIsRemind]").first().text();
    var IsAllVisual = $(contr).parent().parent().find("lable[name=lblIsAllVisual]").first().text();
    var EmptyUnit = $(contr).parent().parent().find("lable[name=lblEmptyUnit]").first().text();
    var isReachCondition = $(contr).parent().parent().find("lable[name=IsReachCondition]").first().text();
    var state = $(contr).parent().parent().find("lable[name=lblState]").first().text();
    var taskcontent = $(contr).parent().parent().find("lable[name=lblContent]").first().text();
    var remark = $(contr).parent().parent().find("lable[name=lblRemark]").first().attr("title");
    var image = $(contr).parent().parent().find("lable[name=lblImage]").first().text();
    var initGold = $(contr).parent().parent().find("lable[name=lblInitGold]").first().text();
    var sortNum = $(contr).parent().parent().find("lable[name=lblSortNum]").first().text();
    var IsUseStage = $(contr).parent().parent().find("lable[name=IsIsUseStage]").first().text();

    if (contr != null) {
        content = "</br><table><tr><td>任务名称：<input type='text' id='txtName' value='" + name + "' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>任务内容：<input type='text' id='txtContent' value='" + taskcontent + "' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>任务描述：<textarea  cols='50' rows='5' id='txtRemark' style='width:197px;float:right'>" + remark + "</textarea></td></tr>";
        content += "<tr><td>初始比赛币：<input type='text' id='txtInitGold' value='" + initGold + "' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>图片号：<input type='text' id='txtImage' value='" + image + "' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>排序号：<input type='text' id='txtSortNum' value='" + sortNum + "' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>开始时间：<input type='text' id='txtStartTime' value='" + startTime + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})\" class=\"Wdate\"  style='width:200px' /></td></tr>";
        content += "<tr><td>结束时间：<input type='text' id='txtEndTime' value='" + endTime + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})\" class=\"Wdate\"  style='width:200px' /></td></tr>";
        if (isRemind == "True")
            content += "<tr><td>是否公告提醒：<input type='radio' name='radioIsRemind' id='radioisTure' value='True' checked='checked' /><lable>是</lable><input type='radio' name='radioIsRemind' id='radioisfalse' value='False'/><lable>否</lable></td></tr>";
        else
            content += "<tr><td>是否公告提醒：<input type='radio' name='radioIsRemind' id='radioisTure' value='True' /><lable>是</lable><input type='radio' name='radioIsRemind' id='radioisfalse' value='False' checked='checked'/><lable>否</lable></td></tr>";
        content += IsAllVisual == "True" ? "<tr><td>是否所有人可见：<input type='radio' name='radioIsAllVisual' id='radioisTure' value='True' checked='checked' /><lable>是</lable><input type='radio' name='radioIsAllVisual' id='radioisfalse' value='False'/><lable>否</lable></td></tr>"
                   : "<tr><td>是否所有人可见：<input type='radio' name='radioIsAllVisual' id='radioisTure' value='True'/><lable>是</lable><input type='radio' name='radioIsAllVisual' id='radioisfalse' value='False' checked='checked'/><lable>否</lable></td></tr>";
        content += "<tr><td>用户任务清空单位：<input type='radio' name='radioEmptyUnit' id='radioisNo' value='0' " + EmptyUnitChecked(EmptyUnit, "不清空") + " /><lable>不清空</lable>";
        content += "<input type='radio' name='radioEmptyUnit' id='radioisDay' value='1' " + EmptyUnitChecked(EmptyUnit, "天") + " /><lable>天</lable>";
        content += "<input type='radio' name='radioEmptyUnit' id='radioisWeek' value='2'  " + EmptyUnitChecked(EmptyUnit, "周") + " /><lable>周</lable>";
        content += "<input type='radio' name='radioEmptyUnit' id='radioisMonth' value='3' " + EmptyUnitChecked(EmptyUnit, "月") + " /><lable>月</lable>";
        content += "<input type='radio' name='radioEmptyUnit' id='radioisYear' value='4' " + EmptyUnitChecked(EmptyUnit, "年") + " /><lable>年</lable></td></tr>";
        if (isReachCondition == "True")
            content += "<tr><td>达到条件即可获取奖品：<input type='radio' name='radioIsReachCondition' id='radioisTure' value='True' checked='checked' /><lable>是</lable><input type='radio' name='radioIsReachCondition' id='radioisfalse' value='False'/><lable>否</lable></td></tr>";
        else
            content += "<tr><td>达到条件即可获取奖品：<input type='radio' name='radioIsReachCondition' id='radioisTure' value='True' /><lable>是</lable><input type='radio' name='radioIsReachCondition' id='radioisfalse' value='False' checked='checked'/><lable>否</lable></td></tr>";
        if (IsUseStage == "True")
            content += "<tr><td>是否可用道具：<input type='radio' name='radioIsUseStage' id='radioisIsUseStageTure' value='True' checked='checked' /><lable>是</lable><input type='radio' name='radioIsUseStage' id='radioisIsUseStagefalse' value='False' /><lable>否</lable></td></tr>";
        else
            content += "<tr><td>是否可用道具：<input type='radio' name='radioIsUseStage' id='radioisIsUseStageTure' value='True' /><lable>是</lable><input type='radio' name='radioIsUseStage' id='radioisIsUseStagefalse' value='False'  checked='checked' /><lable>否</lable></td></tr>";
        content += "</table></br>";
    }
    else {
        content = "</br><table><tr><td>任务名称：<input type='text' id='txtName' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>任务内容：<input type='text' id='txtContent' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>任务描述：<textarea  cols='50' rows='5' id='txtRemark' style='width:197px;float:right'></textarea></td></tr>";
        content += "<tr><td>初始比赛币：<input type='text' id='txtInitGold' value='0' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>图片号：<input type='text' id='txtImage' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>排序号：<input type='text' id='txtSortNum' style='width:200px;float:right' /></td></tr>";
        content += "<tr><td>开始时间：<input type='text' id='txtStartTime'style='width:200px;float:right' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})\" class=\"Wdate\"  /></td></tr>";
        content += "<tr><td>结束时间：<input type='text' id='txtEndTime'style='width:200px;float:right' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})\" class=\"Wdate\"  /></td></tr>";
        content += "<tr><td>是否公告提醒：<input type='radio' name='radioIsRemind' id='radioisTure' value='True' /><lable>是</lable><input type='radio' name='radioIsRemind' id='radioisfalse'  checked='checked' value='False'/><lable>否</lable></td></tr>";
        content += "<tr><td>是否所有人可见：<input type='radio' name='radioIsAllVisual' id='radioisTure' value='True' checked='checked' /><lable>是</lable>"
        content += "<input type='radio' name='radioIsAllVisual' id='radioisfalse' value='False'/><lable>否</lable></td></tr>";
        content += "<tr><td>用户任务清空单位：<input type='radio' name='radioEmptyUnit' id='radioisNo' value='0' checked='checked' /><lable>不清空</lable>";
        content += "<input type='radio' name='radioEmptyUnit' id='radioisDay' value='1'/><lable>天</lable>";
        content += "<input type='radio' name='radioEmptyUnit' id='radioisWeek' value='2'/><lable>周</lable>";
        content += "<input type='radio' name='radioEmptyUnit' id='radioisMonth' value='3'/><lable>月</lable>";
        content += "<input type='radio' name='radioEmptyUnit' id='radioisYear' value='4'/><lable>年</lable></td></tr>";
        content += "<tr><td>达到条件即可获取奖品：<input type='radio' name='radioIsReachCondition' id='radioisTure' value='True' /><lable>是</lable><input type='radio' name='radioIsReachCondition' id='radioisfalse' value='False' checked='checked'/><lable>否</lable></td></tr>";
        content += "<tr><td>是否可用道具：<input type='radio' name='radioIsUseStage' id='radioisIsUseStageTure' value='True' checked='checked' /><lable>是</lable><input type='radio' name='radioIsUseStage' id='radioisIsUseStagefalse' value='False' /><lable>否</lable></td></tr>";
        content += "</table></br>";
    }
    $.dialog({
        title: "更新概率模板",
        content: content,
        button: [
                    {
                        name: "提交",
                        callback: function () {
                            var objName = $("#txtName").val();
                            if ($.trim(objName) == "") {
                                $.dialog.alert("请输入任务名称！");
                                return false;
                            }
                            AddTaskMould(contr, $("#txtName"));
                        }
                    },
                    {
                        name: "取消",
                        callback: function () {
                            this.close();
                        }
                    }
                    ],
        lock: true,
        drag: false
    });
}

function AddTaskMould(contr, txtName) {

    var name = $(txtName).val();
    var content = $(txtName).parent().parent().parent().find("#txtContent").val();
    var remark = $(txtName).parent().parent().parent().find("#txtRemark").val();
    var image = $(txtName).parent().parent().parent().find("#txtImage").val();
    var startTime = $(txtName).parent().parent().parent().find("#txtStartTime").val();
    var endTime = $(txtName).parent().parent().parent().find("#txtEndTime").val();
    var isRemind = $(txtName).parent().parent().parent().find("input[name=radioIsRemind]:checked").val();
    var isIsAllVisual = $(txtName).parent().parent().parent().find("input[name=radioIsAllVisual]:checked").val();
    var isEmptyUnit = $(txtName).parent().parent().parent().find("input[name=radioEmptyUnit]:checked").val();
    var isReachCondition = $(txtName).parent().parent().parent().find("input[name=radioIsReachCondition]:checked").val();
    var id = $(contr).parent().parent().find("lable[name=lblName]").attr("id");
    var initGold = $(txtName).parent().parent().parent().find("#txtInitGold").val();
    var sortNum = $(txtName).parent().parent().parent().find("#txtSortNum").val();
    var IsUseStage = $(txtName).parent().parent().parent().find("input[name=radioIsUseStage]:checked").val();


    var typeID = $("#lblTypeID").attr("name");

    var data = contr == null ?
    {
        action: "Add", typeID: typeID, name: name, startTime: startTime, endTime: endTime, image: image, initGold: initGold, sortNum: sortNum,
        isRemind: isRemind, IsAllVisual: isIsAllVisual, EmptyUnit: isEmptyUnit, isReachCondition: isReachCondition, content: content, remark: remark, IsUseStage: IsUseStage
    } :
    {
        action: "Update", id: id, name: name, startTime: startTime, endTime: endTime, isRemind: isRemind, IsAllVisual: isIsAllVisual, sortNum: sortNum,
        EmptyUnit: isEmptyUnit, isReachCondition: isReachCondition, content: content, remark: remark, image: image, initGold: initGold, IsUseStage: IsUseStage
    };

    $.ajax({
        type: "post",
        data: data,
        async: true,
        url: "../../Ajax/TaskAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                $.dialog.tips("更新成功！", 1);
                var info = data.split('|'); //id|createTime
                if (contr == null) {
                    var tbody = "<tr>";
                    tbody += "<tr>"
                    tbody += "<td><lable name='lblName' id='" + info[0] + "'>";
                    tbody += name;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblContent' >";
                    tbody += content;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblRemark' title='" + remark + "' >";
                    tbody += remark.substr(0, 25); ;
                    tbody += "</label></td>"
                    tbody += "<td><lable name='lblInitGold' >";
                    tbody += initGold;
                    tbody += "</label></td>"
                    tbody += "<td><lable name='lblImage' >";
                    tbody += image;
                    tbody += "</label></td>"
                    tbody += "<td><lable name='lblSortNum' >";
                    tbody += sortNum;
                    tbody += "</label></td>"
                    tbody += "<td><lable name='lblCreateTime' >";
                    tbody += info[1];
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblStartTime'>";
                    tbody += startTime;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblEndTime'>";
                    tbody += endTime;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblIsRemind'>";
                    tbody += isRemind;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblIsAllVisual'>";
                    tbody += isIsAllVisual;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblEmptyUnit'>";
                    tbody += $(txtName).parent().parent().parent().find("input[name=radioEmptyUnit]:checked").next().text();
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblState'>";
                    tbody += "未开始";
                    tbody += "</label></td>";
                    tbody += "<td><lable name='IsReachCondition'>";
                    tbody += isReachCondition;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='IsIsUseStage'>";
                    tbody += IsUseStage;
                    tbody += "</label></td>";
                    tbody += "<td>";
                    tbody += "<input type='button' onclick='UpdateTask(this)' value='更新'><input type='button' onclick='DeleteTask(this)' value='删除'><input type='button' onclick='ArraySave(this)' value='批量生成'>";
                    tbody += "</td>";
                    tbody += "</tr>"
                    $("#tb2").append(tbody);
                }
                else {
                    $(contr).parent().parent().find("lable[name=lblName]").first().text(name);
                    $(contr).parent().parent().find("lable[name=lblSortNum]").first().text(sortNum);
                    $(contr).parent().parent().find("lable[name=lblContent]").first().text(content);
                    $(contr).parent().parent().find("lable[name=lblRemark]").first().text(remark);
                    $(contr).parent().parent().find("lable[name=lblInitGold]").first().text(initGold);
                    $(contr).parent().parent().find("lable[name=lblImage]").first().text(image);
                    $(contr).parent().parent().find("lable[name=lblEndTime]").first().text(endTime);
                    $(contr).parent().parent().find("lable[name=lblIsRemind]").first().text(isRemind);
                    $(contr).parent().parent().find("lable[name=lblIsAllVisual]").first().text(isIsAllVisual);
                    $(contr).parent().parent().find("lable[name=lblEmptyUnit]").first().text($(txtName).parent().parent().parent().find("input[name=radioEmptyUnit]:checked").next().text());
                    $(contr).parent().parent().find("lable[name=IsReachCondition]").first().text($(txtName).parent().parent().parent().find("input[name=radioIsReachCondition]:checked").val());
                    $(contr).parent().parent().find("lable[name=IsIsUseStage]").first().text(IsUseStage);
                }
            }
            else {
                $.dialog.tips("更新失败！", 1);
            }
        },
        complete: function () {
        },
        error: function () {
        }
    })
}

function DeleteTask(contr) {
    var id = $(contr).parent().parent().find("lable[name=lblName]").first().attr("id");
    if (window.confirm("确认删除？")) {
        $.ajax({
            type: "post",
            data: { action: "Delete", id: id },
            async: true,
            url: "../../Ajax/TaskAjax.ashx",
            beforeSend: function () {
            },
            success: function (data) {
                if (data == "True") {
                    $($(contr).parent().parent()).remove();
                    $.dialog.tips("删除成功！", 1);
                }
                else {
                    $.dialog.tips("删除失败！", 1);
                }
            },
            complete: function () {
            },
            error: function () {
            }
        })
    }
}

var pageSize = 10;

function EditLblTypeID(typeID, name) {
    $("#lblTypeID").attr("name", typeID);
    $("#lblTypeID").text(name);
}

function GetTaskList(pageclickednumber) {
    var typeID = $("#lblTypeID").attr("name");
    $.ajax({
        type: "post",
        data: { action: "GetList", typeID: typeID, pageIndex: pageclickednumber, pageSize: pageSize },
        dataType: "json",
        url: "../../Ajax/TaskAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                var json = data.json;
                var pageCount = data.flag;
                var tbody = "";
                $.each(json, function (k, v) {
                    tbody += "<tr>"
                    tbody += "<td><lable name='lblName' id='" + v.ID + "'>";
                    tbody += v.Name;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblContent' >";
                    tbody += v.TaskContent;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblRemark' title='" + decodeURIComponent(v.TaskRemark) + "' >";
                    tbody += decodeURIComponent(v.TaskRemark).substr(0, 25);
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblInitGold' >";
                    tbody += v.InitGold;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblImage' >";
                    tbody += v.ImageType;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblSortNum' >";
                    tbody += v.SortNum;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblCreateTime' >";
                    tbody += v.CrateTime;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblStartTime'>";
                    tbody += v.StartTime;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblEndTime'>";
                    tbody += v.EndTime;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblIsRemind'>";
                    tbody += v.IsRemind;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblIsAllVisual'>";
                    tbody += v.IsAllVisual;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblEmptyUnit'>";
                    tbody += v.EmptyUnitName;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='lblState'>";
                    tbody += v.StateName;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='IsReachCondition'>";
                    tbody += v.IsReachCondition;
                    tbody += "</label></td>";
                    tbody += "<td><lable name='IsIsUseStage'>";
                    tbody += v.IsUseStage;
                    tbody += "</label></td>";
                    tbody += "<td>";
                    tbody += "<input type='button' onclick='UpdateTask(this)' value='更新'><input type='button' onclick='DeleteTask(this)' value='删除'>";
                    tbody += "<input type='button' onclick='ArraySave(this)' value='批量生成'><input type='button' onclick='RobotPram(this)' value='机器人参数'>";
                    tbody += "</td>";
                    tbody += "</tr>"
                })
                $("#tb2").empty().append(tbody);
                $("#pager").pager({ pagenumber: pageclickednumber, pagecount: Math.ceil(pageCount / pageSize), buttonClickCallback: GetTaskList });
            }
        },
        complete: function () {
        },
        error: function () {
        }
    });
}

function RobotPram(contr) {
    var taskID = $(contr).parent().parent().find("lable[name=lblName]").first().attr("id");
    var taskName = $(contr).parent().parent().find("lable[name=lblName]").first().text();

    $.ajax({
        type: "post",
        data: { action: "GetModelByTaskID", taskID: taskID },
        url: "../../Ajax/TaskRobotSettingAjax.ashx",
        dataType: "json",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                var content = "";
                content += "<table><tr><td>任务名称:<lable>" + taskName + "</label><lable style='display:none' id='lblSettingID'>" + data._id + "</label></td></tr>";
                content += "<tr><td>机器人加入间隔（秒）:<input type='text' id='txtRobotAddTime' value='" + (data._robotaddtime == null ? "" : data._robotaddtime) + "' /></td></tr>";
                content += "<tr><td>自动加积分（秒）:<input type='text' id='txtScoreEditTime' value='" + (data._scoreedittime == null ? "" : data._scoreedittime) + "' /></td></tr>";
                content += "<tr><td>最小积分:<input type='text' id='txtMinScore' value='" + (data._minscore == null ? "" : data._minscore) + "' /></td></tr>";
                content += "<tr><td>最大积分:<input type='text' id='txtMaxScore' value='" + (data._maxscore == null ? "" : data._maxscore) + "' /></td></tr>";
                content += "<tr><td>机器人id段最小id:<input type='text' id='txtRobotMinIndex' value='" + (data._robotminindex == null ? "" : data._robotminindex) + "' /></td></tr>";
                content += "<tr><td>机器人id段最大id:<input type='text' id='txtRobotMaxIndex' value='" + (data._robotmaxindex == null ? "" : data._robotmaxindex) + "' /></td></tr>";
                content += "<tr><td>加入机器人最小数量:<input type='text' id='txtRobotMinCount' value='" + (data._robotmincount == null ? "" : data._robotmincount) + "' /></td></tr>";
                content += "<tr><td>加入机器人最大数量:<input type='text' id='txtRobotMaxCount' value='" + (data._robotmaxcount == null ? "" : data._robotmaxcount) + "' /></td></tr>";
                content += "<tr><td>机器人初始分数最小值:<input type='text' id='txtRobotInitMinScore' value='" + (data._robotinitminscore == null ? "" : data._robotinitminscore) + "' /></td></tr>";
                content += "<tr><td>机器人初始分数最大值:<input type='text' id='txtRobotInitMaxScore' value='" + (data._robotinitmaxscore == null ? "" : data._robotinitmaxscore) + "' /></td></tr>";
                content += "</table>";
                $.dialog({
                    title: "机器人参数",
                    content: content,
                    button: [
                    {
                        name: "提交",
                        callback: function () {
                            var id = $("#lblSettingID").text();
                            var robotAddTime = $("#txtRobotAddTime").val();
                            var scoreEditTime = $("#txtScoreEditTime").val();
                            var minScore = $("#txtMinScore").val();
                            var maxScore = $("#txtMaxScore").val();
                            var robotMinIndex = $("#txtRobotMinIndex").val();
                            var robotMaxIndex = $("#txtRobotMaxIndex").val();
                            var robotMinCount = $("#txtRobotMinCount").val();
                            var robotMaxCount = $("#txtRobotMaxCount").val();
                            var robotInitMinScore = $("#txtRobotInitMinScore").val();
                            var robotInitMaxScore = $("#txtRobotInitMaxScore").val();
                            if (robotAddTime == "" || scoreEditTime == "" || minScore == "" || maxScore == "" || robotMinIndex == "" || robotMaxIndex == "" || robotMinCount == "" || robotMaxCount == "" || robotInitMinScore == "" || robotInitMaxScore == "") {
                                $.dialog.alert("请正确输入参数，不可为空！");
                            }
                            else {
                                $.ajax({
                                    type: "post",
                                    data: { action: "Edit", id: id, taskID: taskID, robotAddTime: robotAddTime, scoreEditTime: scoreEditTime, minScore: minScore, maxScore: maxScore, robotMinIndex: robotMinIndex, robotMaxIndex: robotMaxIndex,
                                        robotMinCount: robotMinCount, robotMaxCount: robotMaxCount, robotInitMinScore: robotInitMinScore, robotInitMaxScore: robotInitMaxScore
                                    },
                                    dataType: "json",
                                    async: false,
                                    url: "../../Ajax/TaskRobotSettingAjax.ashx",
                                    beforeSend: function () {
                                    },
                                    success: function (data) {
                                    },
                                    complete: function () {
                                    },
                                    error: function () {
                                    }
                                });
                            }
                        }
                    },
                    {
                        name: "取消",
                        callback: function () {
                            this.close();
                        }
                    }
                    ],
                    lock: true,
                    drag: false

                });
            }
        },
        complete: function () {
        },
        error: function () {
        }
    })
}


function ArraySave(contr) {
    var taskID = $(contr).parent().parent().find("lable[name=lblName]").first().attr("id");
    var content = "<table><tr><td>批量生成场次:<input type='text' id='txtTaskNum' /></td></tr></table>";
    $.dialog({
        title: "生成场次",
        content: content,
        button: [
                    {
                        name: "提交",
                        callback: function () {
                            if ($("#txtTaskNum").val() == "") {
                                $.dialog.alert("请输入生成场次！");
                            }
                            else {
                                AddTaskArray(taskID, $("#txtTaskNum").val());
                            }
                        }
                    },
                    {
                        name: "取消",
                        callback: function () {
                            this.close();
                        }
                    }
                    ],
        lock: true,
        drag: false

    });
}

function AddTaskArray(taskID, taskNum) {
    $.ajax({
        type: "post",
        data: { action: "AddArrayTask", taskID: taskID, taskNum: taskNum },
        async: true,
        url: "../../Ajax/TaskAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data == "True") {
                $.dialog.tips("批量生成成功！", 1);
            }
            else {
                $.dialog.tips("批量生成失败！", 1);
            }
        },
        complete: function () {
        },
        error: function () {
        }
    })
}

function Delete(contr) {
    var id = $(contr).parent().parent().find("lable[name=lblID]").first().text();
    if (window.confirm("确认删除？")) {
        $.ajax({
            type: "post",
            data: { action: "Delete", id: id },
            async: true,
            url: "../../Ajax/TaskTypeAjax.ashx",
            beforeSend: function () {
            },
            success: function (data) {
                if (data == "True") {
                    $($(contr).parent().parent()).remove();
                    $.dialog.tips("删除成功！", 1);
                }
                else {
                    $.dialog.tips("删除失败！", 1);
                }
            },
            complete: function () {
            },
            error: function () {
            }
        })
    }
}


function Update(contr) {
    Edit(contr);
}

function Edit(contr) {
    var id = $(contr).parent().parent().find("lable[name=lblID]").first().text();
    var name = $(contr).parent().parent().find("lable[name=lblName]").first().text();
    var content = "";
    if (contr != null)
        content = "<table><tr><td>任务类型名称：<input type='text' id='txtName' value='" + name + "' style='width:200px;float:right' /></td></tr></table>";
    else
        content = "<table><tr><td>任务类型id：<input type='text' id='txtID' style='width:200px;float:right' /></td></tr>"
                + "<tr><td>任务类型名称：<input type='text' id='txtName' style='width:200px;float:right' /></td></tr></table>";
    $.dialog({
        title: "更新概率模板",
        content: content,
        button: [
                    {
                        name: "提交",
                        callback: function () {
                            if (contr == null) {
                                id = $("#txtID").val()
                            }
                            if ($.trim(id) == "") {
                                $.dialog.alert("请输入任务类型id！");
                                return false;
                            }
                            var objName = $("#txtName").val();
                            if ($.trim(objName) == "") {
                                $.dialog.alert("请输入任务类型名称！");
                                return false;
                            }
                            AddMould(contr, id, objName);
                        }
                    },
                    {
                        name: "取消",
                        callback: function () {
                            this.close();
                        }
                    }
                    ],
        lock: true,
        drag: false

    });
}

function AddMould(contr, id, name) {
    var data = contr == null ? { action: "Add", id: id, name: name} :
              { action: "Update", id: id, name: name };
    $.ajax({
        type: "post",
        data: data,
        async: true,
        url: "../../Ajax/TaskTypeAjax.ashx",
        beforeSend: function () {
        },
        success: function (data) {
            if (data != null) {
                $.dialog.tips("更新成功！", 1);
                var info = data.split('|'); //id|createTime|imgPath
                if (contr == null) {
                    var tbody = "<tr>";
                    tbody += "<td><lable name='lblID'>";
                    tbody += id;
                    tbody += "</label></td>";
                    tbody += "<td><a href='javascript:void(0)' onclick='javascript:EditLblTypeID(\"" + id + "\",\"" + name + "\");GetTaskList(1)'><lable name='lblName'>";
                    tbody += name;
                    tbody += "</label></a></td>";
                    tbody += "<td>";
                    tbody += "<input type='button' onclick='Update(this)' value='更新'><input type='button' onclick='Delete(this)' value='删除'>";
                    tbody += "</td>";
                    tbody += "</tr>"
                    $("#tb1").append(tbody);
                }
                else {
                    $(contr).parent().parent().find("lable[name=lblID]").first().text(id);
                    $(contr).parent().parent().find("lable[name=lblName]").first().text(name);
                }
            }
            else {
                $.dialog.tips("更新失败！", 1);
            }
        },
        complete: function () {
        },
        error: function () {
        }
    })
}